package edu.thu.studio.ormdesigner.outline.command;

import edu.thu.studio.ormdesigner.common.AbstractCommand;
import edu.thu.studio.ormdesigner.model.ORMModel;
import edu.thu.studio.ormdesigner.model.diagram.Diagram;
import edu.thu.studio.ormdesigner.model.diagram.DiagramSet;

public class CreateDiagramCommand extends AbstractCommand {
    
    private DiagramSet diagrams;
    
    private Diagram diagram;
    
    public CreateDiagramCommand(ORMModel model, Diagram diagram) {
        this.diagrams = model.getDiagrams();
        this.diagram = diagram;
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doExecute() {
        diagrams.addObject(diagram);
        diagrams.refresh();
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doUndo() {
        diagrams.remove(diagram);
        diagrams.refresh();
    }
}
